package com.ankiang.treeprint.manager;

import android.content.Context;

import com.ankiang.treeprint.base.BaseFragment;
import com.ankiang.treeprint.fragment.components.QDBottomSheetFragment;
import com.ankiang.treeprint.fragment.components.QDButtonFragment;
import com.ankiang.treeprint.fragment.components.QDCollapsingTopBarLayoutFragment;
import com.ankiang.treeprint.fragment.components.QDDialogFragment;
import com.ankiang.treeprint.fragment.components.QDEmptyViewFragment;
import com.ankiang.treeprint.fragment.components.QDFloatLayoutFragment;
import com.ankiang.treeprint.fragment.components.QDLinkTextViewFragment;
import com.ankiang.treeprint.fragment.components.QDPopupFragment;
import com.ankiang.treeprint.fragment.components.QDProgressBarFragment;
import com.ankiang.treeprint.fragment.components.QDPullRefreshFragment;
import com.ankiang.treeprint.fragment.components.QDSpanTouchFixTextViewFragment;
import com.ankiang.treeprint.fragment.components.QDTabSegmentFragment;
import com.ankiang.treeprint.fragment.components.QDTipDialogFragment;
import com.ankiang.treeprint.fragment.components.QDVerticalTextViewFragment;
import com.ankiang.treeprint.fragment.components.TRAddItemFragment;
import com.ankiang.treeprint.fragment.components.TRAddresMapFragment;
import com.ankiang.treeprint.fragment.components.TRCalculatorFragment;
import com.ankiang.treeprint.fragment.components.TRGalleryFragment;
import com.ankiang.treeprint.fragment.components.TRGenPhotoFragment;
import com.ankiang.treeprint.fragment.components.TRGiftSuggestFragment;
import com.ankiang.treeprint.fragment.components.TRGroupPhotoFragment;
import com.ankiang.treeprint.fragment.components.TRHelpFragment;
import com.ankiang.treeprint.fragment.components.TRHomeTreeFragment;
import com.ankiang.treeprint.fragment.components.TRRedpacketDistributeFragment;
import com.ankiang.treeprint.fragment.components.TRSearchItemFragment;
import com.ankiang.treeprint.fragment.components.TRSeekPicFragment;
import com.ankiang.treeprint.fragment.components.TRSettingsFragment;
import com.ankiang.treeprint.fragment.components.TRSinglePhotoFragment;
import com.ankiang.treeprint.fragment.components.TRTimeFlyFragment;
import com.ankiang.treeprint.fragment.components.qqface.QDQQFaceFragment;
import com.ankiang.treeprint.fragment.components.viewpager.QDViewPagerFragment;
import com.ankiang.treeprint.fragment.lab.QDAnimationListViewFragment;
import com.ankiang.treeprint.fragment.lab.QDArchTestFragment;
import com.ankiang.treeprint.fragment.lab.QDSnapHelperFragment;
import com.ankiang.treeprint.fragment.util.QDSpanFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * @author cginechen
 * @date 2016-10-21
 */

public class QDDataManager {
    private static QDDataManager _sInstance;
    private final Context context;
    private QDWidgetContainer mWidgetContainer;

    private List<Class<? extends BaseFragment>> mComponentsNames;
    private List<Class<? extends BaseFragment>> mSeekpicNames;
    private List<Class<? extends BaseFragment>> mHomeNames;

    public QDDataManager(Context context) {
        mWidgetContainer = QDWidgetContainer.getInstance(context);
        this.context = context;

        initComponentsDesc();
        initSeekpicDesc();
        initHomeDesc();
        initLabDesc();
    }

    public static QDDataManager getInstance(Context context) {
        if (_sInstance == null) {
            _sInstance = new QDDataManager(context);
        }
        return _sInstance;
    }


    /**
     * Components
     */
    private void initComponentsDesc() {
        mComponentsNames = new ArrayList<>();
        mComponentsNames.add(TRAddItemFragment.class);
        mComponentsNames.add(TRSearchItemFragment.class);
        mComponentsNames.add(TRSettingsFragment.class);

        mComponentsNames.add(QDButtonFragment.class);
        mComponentsNames.add(QDDialogFragment.class);
        mComponentsNames.add(QDFloatLayoutFragment.class);
        mComponentsNames.add(QDEmptyViewFragment.class);
        mComponentsNames.add(QDTabSegmentFragment.class);
        mComponentsNames.add(QDProgressBarFragment.class);
        mComponentsNames.add(QDBottomSheetFragment.class);
        mComponentsNames.add(QDTipDialogFragment.class);
        mComponentsNames.add(QDVerticalTextViewFragment.class);
        mComponentsNames.add(QDPullRefreshFragment.class);
        mComponentsNames.add(QDPopupFragment.class);
        mComponentsNames.add(QDSpanTouchFixTextViewFragment.class);
        mComponentsNames.add(QDLinkTextViewFragment.class);
        mComponentsNames.add(QDQQFaceFragment.class);
        mComponentsNames.add(QDSpanFragment.class);
        mComponentsNames.add(QDCollapsingTopBarLayoutFragment.class);
        mComponentsNames.add(QDViewPagerFragment.class);
    }

    /**
     * Seekpic
     */
    private void initSeekpicDesc() {
        mSeekpicNames = new ArrayList<>();

        mSeekpicNames.add(TRSeekPicFragment.class);
        mSeekpicNames.add(TRGroupPhotoFragment.class);
        mSeekpicNames.add(TRTimeFlyFragment.class);
        mSeekpicNames.add(TRSinglePhotoFragment.class);
        mSeekpicNames.add(TRGenPhotoFragment.class);
        mSeekpicNames.add(TRGalleryFragment.class);
    }

    /**
     * Lab
     */
    private void initLabDesc() {
        List<Class<? extends BaseFragment>> mLabNames = mComponentsNames;
        mLabNames.add(QDAnimationListViewFragment.class);
        mLabNames.add(QDSnapHelperFragment.class);
        mLabNames.add(QDArchTestFragment.class);
    }

    /**
     * Lab
     */
    private void initHomeDesc() {
        mHomeNames = new ArrayList<>();
        mHomeNames.add(TRHomeTreeFragment.class);
        mHomeNames.add(TRCalculatorFragment.class);
        mHomeNames.add(TRSeekPicFragment.class);
        mHomeNames.add(TRHelpFragment.class);
        mHomeNames.add(TRGiftSuggestFragment.class);
        mHomeNames.add(TRRedpacketDistributeFragment.class);
        mHomeNames.add(TRAddresMapFragment.class);
        mHomeNames.add(TRGroupPhotoFragment.class);
    }

    public QDItemDescription getDescription(Class<? extends BaseFragment> cls) {
        return mWidgetContainer.get(cls);
    }

    public String getName(Class<? extends BaseFragment> cls) {
        QDItemDescription itemDescription = getDescription(cls);
        if (itemDescription == null) {
            return null;
        }
        return itemDescription.getName();
    }

    public List<QDItemDescription> getComponentsDescriptions() {
        List<QDItemDescription> list = new ArrayList<>();
        for (int i = 0; i < mComponentsNames.size(); i++) {
            list.add(mWidgetContainer.get(mComponentsNames.get(i)));
        }
        return list;
    }
    public List<QDItemDescription> getHomeDescriptions() {
        List<QDItemDescription> list = new ArrayList<>();
        for (int i = 0; i < mHomeNames.size(); i++) {
            list.add(mWidgetContainer.get(mHomeNames.get(i)));
        }
        return list;
    }

    public List<QDItemDescription> getSeekpicDescriptions() {
        List<QDItemDescription> list = new ArrayList<>();
        for (int i = 0; i < mSeekpicNames.size(); i++) {
            list.add(mWidgetContainer.get(mSeekpicNames.get(i)));
        }
        return list;
    }

    public List<QDItemDescription> getLabDescriptions() {
        List<QDItemDescription> list = new ArrayList<>();
//        for (int i = 0; i < mLabNames.size(); i++) {
//            list.add(mWidgetContainer.get(mLabNames.get(i)));
//        }
        return list;
    }

    public List<QDItemDescription> getMeDescriptions() {
        List<QDItemDescription> list = new ArrayList<>();
        return list;
    }

    /**
     * @author cginechen
     * @date 2016-10-21
     */

    public static class QDItemDescription {
        private Class<? extends BaseFragment> mKitDemoClass;
        private String mKitName;
        private String mKitDetailDescription;
        private int mIconRes;

        public QDItemDescription(Class<? extends BaseFragment> kitDemoClass, String kitName){
            this(kitDemoClass, kitName, 0);
        }


        public QDItemDescription(Class<? extends BaseFragment> kitDemoClass, String kitName, int iconRes) {
            mKitDemoClass = kitDemoClass;
            mKitName = kitName;
            mIconRes = iconRes;
        }

        public QDItemDescription(Class<? extends BaseFragment> kitDemoClass, String kitName,
                                 String kitDetailDescription, int iconRes) {
            mKitDemoClass = kitDemoClass;
            mKitName = kitName;
            mKitDetailDescription = kitDetailDescription;
            mIconRes = iconRes;
        }

        public void setItemDetailDescription(String kitDetailDescription) {
            mKitDetailDescription = kitDetailDescription;
        }

        public Class<? extends BaseFragment> getDemoClass() {
            return mKitDemoClass;
        }

        public String getName() {
            return mKitName;
        }

        public String getItemDetailDescription() {
            return mKitDetailDescription;
        }

        public int getIconRes() {
            return mIconRes;
        }
    }
}
